﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using AndroidEditor.WForm;
using System.IO;
using System.Diagnostics;
using System.Xml;
using AndroidEditor.SettingClass;
namespace AndroidEditor
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks></remarks>
    public partial class AndroidEditorMainForm : Form
    {


        /// <summary>
        /// Initializes a new instance of the <see cref="AndroidEditorMainForm"/> class.
        /// </summary>
        /// <remarks></remarks>
        public AndroidEditorMainForm()
        {
            InitializeComponent();
        }


        /// <summary>
        /// Handles the Click event of the item control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks></remarks>
        void item_Click(object sender, EventArgs e)
        {
            ToolStripItem menuitem = (ToolStripItem)sender;

        }



        /// <summary>
        /// Handles the Load event of the AndroidEditorMainForm control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks></remarks>
        private void AndroidEditorMainForm_Load(object sender, EventArgs e)
        {
            tableLayoutPanel1.Left = 0;
            tableLayoutPanel1.Height = this.ClientSize.Height - toolStrip.Height - statusStrip.Height;
            tableLayoutPanel1.Top = toolStrip.Top + toolStrip.ClientSize.Height;
            PT.Nodes.Clear();

            InitDocumentTab();
            SetDocumentTabVisable(false);

            SetNDK();
            InitPT();
            DetchAndSetGcc();

        }

        /// <summary>
        /// Inits the PT.
        /// </summary>
        /// <remarks></remarks>
        private void InitPT()
        {
            PT.DoubleClick += new EventHandler(PT_DoubleClick);
        }

        /// <summary>
        /// Handles the DoubleClick event of the PT control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks></remarks>
        void PT_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                TreeNode node = (TreeNode)PT.SelectedNode;
                FileSetting fSetting = (FileSetting)node.Tag;
                AddDocument(fSetting.GetFile());
            }
            catch (Exception ex)
            {
            }
        }

        /// <summary>
        /// Adds the document.
        /// </summary>
        /// <param name="doc">The doc.</param>
        /// <remarks></remarks>
        private void AddDocument(string doc)
        {
            if (DocumentTab.TabPages[doc] != null)
            {
                DocumentTab.SelectedTab = DocumentTab.TabPages[doc];
                return;
            }
            if (DocumentTab.TabPages.Count == 0)
            {
                DocumentTab.Visible = true;
            }
            DocumentTab.TabPages.Add(doc, Path.GetFileName(doc));
            TabPage item = DocumentTab.TabPages[doc];

            SettingClass.ExtensionEditor editor = new AndroidEditor.SettingClass.ExtensionEditor();
            item.Controls.Add(editor);
            item.Resize += new EventHandler(item_Resize);
            item.Tag = editor;
            editor.Focus();
            editor.Width = item.ClientSize.Width;
            editor.Height = item.ClientSize.Height;
            DocumentTab.SelectedTab = item;
            item.Disposed += new EventHandler(item_Disposed);
            editor.Tag = item;
            editor.OpenFile(doc);

        }

        /// <summary>
        /// Handles the Disposed event of the item control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks></remarks>
        void item_Disposed(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// Handles the Resize event of the item control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks></remarks>
        void item_Resize(object sender, EventArgs e)
        {
            SettingClass.ExtensionEditor editor = (SettingClass.ExtensionEditor)DocumentTab.SelectedTab.Tag;
            TabPage page = (TabPage)sender;
            editor.Width = page.ClientSize.Width;
            editor.Height = page.ClientSize.Height;

        }

        /// <summary>
        /// Sets the document tab visable.
        /// </summary>
        /// <param name="visible">if set to <c>true</c> [visible].</param>
        /// <remarks></remarks>
        private void SetDocumentTabVisable(bool visible)
        {
            DocumentTab.Visible = visible;
        }

        /// <summary>
        /// Inits the document tab.
        /// </summary>
        /// <remarks></remarks>
        private void InitDocumentTab()
        {
            DocumentTab.Height = this.ClientSize.Height - toolStrip.Height - statusStrip.Height;
            DocumentTab.Top = tableLayoutPanel1.Top;
            DocumentTab.Left = tableLayoutPanel1.Width;
            DocumentTab.Width = ClientSize.Width - tableLayoutPanel1.Width;
        }



        /// <summary>
        /// Sets the NDK.
        /// </summary>
        /// <remarks></remarks>
        private void SetNDK()
        {
            string path = GlobleSetting.Instance().GetNDK();
            if (path.Trim() == "")
            {
                EnvironmentSetup eSetup = new EnvironmentSetup();
                while (true)
                {

                    eSetup.fromLoad();
                    if (eSetup.ShowDialog() == DialogResult.OK)
                    {
                        GlobleSetting.Instance().SetNDkPath(eSetup.gGetNdkPath());
                        GlobleSetting.Instance().SetCompilerPath(eSetup.GetCompilerPath());
                        return;
                    }
                    else
                    {
                        Process.GetCurrentProcess().Kill();
                    }
                }
            }
        }

        /// <summary>
        /// Handles the Resize event of the AndroidEditorMainForm control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks></remarks>
        private void AndroidEditorMainForm_Resize(object sender, EventArgs e)
        {
            tableLayoutPanel1.Top = toolStrip.Top + toolStrip.ClientSize.Height;

            tableLayoutPanel1.Height = this.ClientSize.Height - toolStrip.Height - statusStrip.Height;
            InitDocumentTab();
        }


        /// <summary>
        /// Handles the SizeChanged event of the tableLayoutPanel1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks></remarks>
        private void tableLayoutPanel1_SizeChanged(object sender, EventArgs e)
        {
            tabControl1.Height = tableLayoutPanel1.Height;
            tabControl1.Top = 0;

        }





        /// <summary>
        /// Handles the AfterSelect event of the treeViewForProject control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.TreeViewEventArgs"/> instance containing the event data.</param>
        /// <remarks></remarks>
        private void treeViewForProject_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (PT.SelectedNode != null)
            {

                switch (TreeNodeType(PT.SelectedNode))
                {
                    case (int)NodeType.工程节点:
                        PT.ContextMenuStrip = ProjectSettingMenu;
                        break;
                    case (int)NodeType.头文件:
                        PT.ContextMenuStrip = HeadSettingMenu;
                        break;
                    case (int)NodeType.源文件:
                        PT.ContextMenuStrip = SourceSettingMenu;
                        break;
                    case (int)NodeType.文件:
                        PT.ContextMenuStrip = FileSettingMenu;
                        break;
                    case (int)NodeType.空间:
                        PT.ContextMenuStrip = 空间菜单;
                        break;

                }
                if (PT.SelectedNode.Text == "头文件")
                {
                }
                if (PT.SelectedNode.Text == "头文件")
                {
                }
            }


        }

        /// <summary>
        /// Trees the type of the node.
        /// </summary>
        /// <param name="treeNode">The tree node.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        private int TreeNodeType(TreeNode treeNode)
        {

            try
            {
                空间设置 设置 = (空间设置)treeNode.Tag;
                return (int)NodeType.空间;
            }
            catch (Exception ex)
            {
            }
            try
            {
                ProjectSetting settingNode = (ProjectSetting)treeNode.Tag;
                return (int)NodeType.工程节点;
            }
            catch (System.Exception ex)
            {

            }

            try
            {
                HeadSetting HeadNode = (HeadSetting)treeNode.Tag;
                return (int)NodeType.头文件;
            }
            catch (System.Exception ex)
            {

            }
            try
            {
                SourceSetting SourceNode = (SourceSetting)treeNode.Tag;
                return (int)NodeType.源文件;
            }
            catch (Exception ex)
            {

            }

            try
            {
                FileSetting fileNode = (FileSetting)treeNode.Tag;
                return (int)NodeType.文件;
            }
            catch (Exception ex)
            {

            }
            return (int)NodeType.未知;
        }







        /// <summary>
        /// Detches the and set GCC.
        /// </summary>
        /// <remarks></remarks>
        private void DetchAndSetGcc()
        {
            DirectoryInfo directory = new DirectoryInfo(GlobleSetting.Instance().GetNDK());
            FileInfo[] gccinfo = directory.GetFiles("arm-linux-androideabi-gcc.exe", SearchOption.AllDirectories);
            if (gccinfo.Length > 0)
            {
                string gccstr = gccinfo[0].Name;
                string Env = System.Environment.GetEnvironmentVariable("path").ToLower();
                gccstr = Path.GetDirectoryName(gccstr).ToLower();


                if (Env.IndexOf(gccstr) == -1)
                {
                    System.Environment.SetEnvironmentVariable("path", gccstr + ";" + Env);
                }
            }
        }






        /// <summary>
        /// Enables the setting.
        /// </summary>
        /// <remarks></remarks>
        private void EnableSetting()
        {
            StopCompileButton.Enabled = false;
            CompileButton.Enabled = true;
            信息ToolStripMenuItem.Visible = true;
        }



        /// <summary>
        /// 
        /// </summary>
        /// <remarks></remarks>
        public enum NodeType
        {
            /// <summary>
            /// 
            /// </summary>
            工程节点 = 0, 头文件, 源文件, 未知,
            文件, 空间
        }

        private void 添加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                HeadSetting pSetting = (HeadSetting)PT.SelectedNode.Tag;
                openFileDialog1.Multiselect = true;
                openFileDialog1.FileName = "";
                openFileDialog1.Filter = "(*.hpp;*.h;*.hxx)|*.hpp;*.h;*.hxx|*|*.*";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    foreach (string Item in openFileDialog1.FileNames)
                    {
                        TreeNode fileNode = PT.SelectedNode.Nodes.Add(Path.GetFileName(Item));
                        FileSetting fSetting = new FileSetting(Item, pSetting);
                        fileNode.Tag = fSetting;
                        pSetting.AddItem(fSetting);

                    }
                    PT.SelectedNode.ExpandAll();
                }
            }
            catch (Exception ex)
            {

            }
        }





        private void 添加文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                SourceSetting pSetting = (SourceSetting)PT.SelectedNode.Tag;
                openFileDialog1.Multiselect = true;
                openFileDialog1.FileName = "";
                openFileDialog1.Filter = "*.cxx;*.c;*.cpp|*.cxx;*.c;*.cpp|*|*.*";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    foreach (string Item in openFileDialog1.FileNames)
                    {
                        TreeNode fileNode = PT.SelectedNode.Nodes.Add(Path.GetFileName(Item));
                        FileSetting fSetting = new FileSetting(Item, pSetting);
                        fileNode.Tag = fSetting;
                        pSetting.AddItem(fSetting);


                    }
                    PT.SelectedNode.ExpandAll();
                }
            }
            catch (Exception ex)
            {

            }
        }




        private void AndroidEditorMainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            GlobleSetting.Instance().Save(GlobleSetting.CurrentDir + @"\Config.xml");
        }





        private void DocumentTab_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DocumentTab.TabPages.Count > 0)
            {
                SettingClass.ExtensionEditor editor = (SettingClass.ExtensionEditor)DocumentTab.SelectedTab.Tag;
                editor.Focus();
            }
        }

        private void 新建空间ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if (PT.Nodes.Count > 0)
            {

                return;
            }
            TreeNode Root = PT.Nodes.Add("RootWorkSpace", "新空间");
            空间设置 设置 = new 空间设置();

            Root.Tag = 设置;

        }

        private void toolStripMenuItem12_Click(object sender, EventArgs e)
        {
            try
            {
                空间设置 tag = (空间设置)PT.SelectedNode.Tag;
                NprojectType settingform = new NprojectType();
                if (settingform.ShowDialog() == DialogResult.OK)
                {
                    ProjectSetting setting = tag.AddProjectSetting(settingform.getProjectName());
                    if (setting == null)
                    {
                        MessageBox.Show("工程已存在！");
                        return;
                    }

                    setting.setCType(settingform.isCPlusPlus());
                    setting.setProjecttype(settingform.GetSelectType());
                    TreeNode ProjectName = PT.SelectedNode.Nodes.Add(settingform.getProjectName());
                    ProjectName.Tag = setting;

                    PT.SelectedNode.ExpandAll();
                    AddNode(ProjectName, setting);
                    ProjectName.ExpandAll();
                }
            }
            catch (Exception ex)
            {
            }
        }

        private void AddNode(TreeNode treeNode, ProjectSetting psetting)
        {
            HeadSetting hs = new HeadSetting(psetting);

            treeNode.Nodes.Add("头文件").Tag = hs;
            psetting.addHead(hs);
            SourceSetting ss = new SourceSetting(psetting);

            treeNode.Nodes.Add("源文件").Tag = ss;
            psetting.addSource(ss);
        }

        private void 空间菜单_Opening(object sender, CancelEventArgs e)
        {

        }

        private void 设置平台ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                空间设置 tag = (空间设置)PT.SelectedNode.Tag;
                AndroidPlatForm apf = new AndroidPlatForm(tag.GetPlatForm());
                if (apf.ShowDialog() == DialogResult.OK)
                {
                    tag.SetPlatForm(apf.GetSelectVersion());
                }
            }
            catch (Exception ex)
            {
            }

        }

        private void toolStripMenuItem10_Click(object sender, EventArgs e)
        {
            try
            {
                ProjectSetting tag = (ProjectSetting)PT.SelectedNode.Tag;
                空间设置 node = (空间设置)PT.SelectedNode.Parent.Tag;
                node.Remove(tag.getProjectName());
                PT.SelectedNode.Remove();

            }
            catch (Exception ex)
            {
            }
        }

        private void 设置CPU信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                空间设置 tag = (空间设置)PT.SelectedNode.Tag;
                CPUForm apf = new CPUForm(tag.isarmeab(), tag.isarmeabv7());
                if (apf.ShowDialog() == DialogResult.OK)
                {
                    tag.SetCpu(apf.CheckBox1(), apf.CheckBox2());
                }
            }
            catch (Exception ex)
            {
            }
        }

        private void 整体编译ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string sysroot = "";
            try
            {
                空间设置 tag = (空间设置)PT.SelectedNode.Tag;
                while (!tag.isSaved())
                {
                    tag.SetSave();
                }
                AndroidPlatForm apf = new AndroidPlatForm(tag.GetPlatForm());
                while (tag.GetPlatForm() == -1)
                {

                    if (apf.ShowDialog() == DialogResult.OK)
                    {
                        tag.SetPlatForm(apf.GetSelectVersion());
                    }
                }


                CPUForm apfcpu = new CPUForm(tag.isarmeab(), tag.isarmeabv7());
                while (tag.isarmeab() == false && tag.isarmeabv7() == false)
                {

                    if (apfcpu.ShowDialog() == DialogResult.OK)
                    {
                        tag.SetCpu(apfcpu.CheckBox1(), apfcpu.CheckBox2());
                    }
                }

                Compiler.CompilerEr er = tag.Compile();
                if (er == null)
                {
                    tabControl1.SelectedTab = tabPage3;
                    textBox1.Text = "编译成功!";
                }
                else
                {
                    tabControl1.SelectedTab = tabPage3;
                    textBox1.Text = er.CompilerLine;
                    textBox1.Text += Environment.NewLine;
                    textBox1.Text += er.ErrorMes;
                }




            }
            catch (Exception ex)
            {
            }
        }

        private void 删除ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            try
            {
                空间设置 tag = (空间设置)PT.SelectedNode.Tag;
                PT.SelectedNode.Remove();
                PT.ContextMenuStrip = CreateWorkSpace;
            }
            catch (Exception ex)
            {
            }
        }

        private void SetupSetting_Click(object sender, EventArgs e)
        {
            try
            {
                ProjectSetting tag = (ProjectSetting)PT.SelectedNode.Tag;

                ProjectProperties properties = new ProjectProperties();
                properties.SetDependHeaderDirectory(tag.GetDependHeaderDirectory());
                properties.SetDependProject(GetDependProjrectWithoutSelf(tag, PT.SelectedNode));
                properties.SetDependLibsDirectory(tag.GetDependLibsDirectory());
                properties.SetVB(tag.GetVB());
                properties.SetJS(tag.GetJS());
                properties.SetIsJS(tag.GetIsJS());
                properties.SetFlags(tag.GetFlags());
                properties.SetLibs(tag.GetLibs());
                if (properties.ShowDialog() == DialogResult.OK)
                {
                    List<string> DependHeaderDirectory = properties.GetDHD();
                    tag.SetDependHeaderDirectory(DependHeaderDirectory);
                    List<string> DependLibsDirectory = properties.GetDLibs();
                    tag.SetDependLibsDirectory(DependLibsDirectory);
                    tag.SetisJs(properties.GetIsJs());
                    tag.SaveJs(properties.GetJS());
                    tag.SaveVB(properties.GetVB());
                    tag.SaveLibs(properties.GetLibs());
                    tag.SaveFlags(properties.GetFlags());


                }

            }
            catch (Exception ex)
            {
            }
        }

        private List<ProjectSetting> GetDependProjrectWithoutSelf(ProjectSetting tag, TreeNode treeNode)
        {

            List<ProjectSetting> DP = new List<ProjectSetting>();
            foreach (TreeNode node in treeNode.Parent.Nodes)
            {
                try
                {
                    ProjectSetting tagItem = (ProjectSetting)node.Tag;
                    if (tagItem != tag && (tagItem.getProjecttype() == NprojectType.PType.动态库 || tagItem.getProjecttype() == NprojectType.PType.静态库))
                    {
                        DP.Add(tagItem);
                    }
                }
                catch (Exception ex)
                {
                }
            }
            return DP;
        }

        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                FileSetting fileNode = (FileSetting)PT.SelectedNode.Tag;
                AddDocument(fileNode.GetFile());

            }
            catch (Exception ex)
            {

            }
        }

        private void ProjectSettingMenu_Opening(object sender, CancelEventArgs e)
        {
            try
            {
                ProjectSetting tag = (ProjectSetting)PT.SelectedNode.Tag;
                if (tag.getCtype() == NprojectType.CType.C)
                {
                    toolStripMenuItem13.Text = "转化为C++工程";
                }
                else
                {
                    toolStripMenuItem13.Text = "转化为C工程";
                }
                if (tag.getProjecttype() == NprojectType.PType.动态库)
                {
                    toolStripMenuItem15.Text = "转为静态库";
                    toolStripMenuItem15.Tag = "static";
                    toolStripMenuItem16.Text = "转为应用程序";
                    toolStripMenuItem16.Tag = "application";
                }
                if (tag.getProjecttype() == NprojectType.PType.静态库)
                {
                    toolStripMenuItem15.Text = "转为动态库";
                    toolStripMenuItem15.Tag = "share";
                    toolStripMenuItem16.Text = "转为应用程序";
                    toolStripMenuItem16.Tag = "application";
                }
                if (tag.getProjecttype() == NprojectType.PType.应用程序)
                {
                    toolStripMenuItem15.Text = "转为静态库";
                    toolStripMenuItem15.Tag = "static";
                    toolStripMenuItem16.Text = "转为动态库";
                    toolStripMenuItem16.Tag = "share";
                }
            }
            catch (Exception ex)
            {

            }
        }

        private void toolStripMenuItem13_Click(object sender, EventArgs e)
        {
            try
            {
                ProjectSetting tag = (ProjectSetting)PT.SelectedNode.Tag;
                if (tag.getCtype() == NprojectType.CType.C)
                {
                    tag.setCType(NprojectType.CType.CPlusPlus);
                }
                else
                {
                    tag.setCType(NprojectType.CType.C);
                }
            }
            catch (Exception ex)
            {

            }
        }


        private void toolStripMenuItem14_Click(object sender, EventArgs e)
        {


            空间设置 tag = (空间设置)PT.SelectedNode.Tag;
            if (!tag.isSaved())
            {
                if (!tag.isSavedToFile())
                {
                    folderBrowserDialog1.SelectedPath = @"c:\";
                    if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                    {
                        tag.SetTagPath(folderBrowserDialog1.SelectedPath);
                        tag.SaveXml();
                        PT.SelectedNode.Text = Path.GetFileName(folderBrowserDialog1.SelectedPath);
                    }

                }
                else
                {
                    tag.SaveXml();
                }
            }
            

        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            SendMail sm = new SendMail();
            if (sm.ShowDialog() == DialogResult.OK)
            {

            }
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            AboutBox ab = new AboutBox();
            ab.ShowDialog();
        }

        private void toolStripMenuItem15_Click(object sender, EventArgs e)
        {


            try
            {
                ProjectSetting tag = (ProjectSetting)PT.SelectedNode.Tag;
                ToolStripMenuItem item = (ToolStripMenuItem)sender;
                string type = item.Tag.ToString();
                if (type == "application")
                {
                    tag.setProjecttype(NprojectType.PType.应用程序);
                }
                if (type == "share")
                {
                    tag.setProjecttype(NprojectType.PType.动态库);
                }
                if (type == "static")
                {
                    tag.setProjecttype(NprojectType.PType.静态库);
                }
            }
            catch (Exception ex)
            {
            }
        }

        private void toolStripMenuItem16_Click(object sender, EventArgs e)
        {
            ProjectSetting tag = (ProjectSetting)PT.SelectedNode.Tag;
            ToolStripMenuItem item = (ToolStripMenuItem)sender;
            string type = item.Tag.ToString();
            if (type == "application")
            {
                tag.setProjecttype(NprojectType.PType.应用程序);
            }
            if (type == "share")
            {
                tag.setProjecttype(NprojectType.PType.动态库);
            }
            if (type == "static")
            {
                tag.setProjecttype(NprojectType.PType.静态库);
            }
        }

        private void tabPage3_Resize(object sender, EventArgs e)
        {
            TabPage Change = (TabPage)sender;
            textBox1.Width = Change.ClientSize.Width;
            textBox1.Height = Change.ClientSize.Height;
        }



        private void tabPage1_Resize(object sender, EventArgs e)
        {
            TabPage Change = (TabPage)sender;
            PT.Top = 0;
            PT.Left = 0;
            PT.Width = Change.ClientSize.Width;
            PT.Height = Change.ClientSize.Height;
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            try
            {
                FileSetting fileNode = (FileSetting)PT.SelectedNode.Tag;
                TreeNode parent = PT.SelectedNode.Parent;

                try
                {
                    HeadSetting hs = (HeadSetting)parent.Tag;
                    hs.Remove(fileNode);

                }
                catch (Exception ex)
                {
                    SourceSetting ss = (SourceSetting)parent.Tag;
                    ss.Remove(fileNode);
                }
                finally
                {

                    PT.SelectedNode.Remove();
                }


            }
            catch (Exception ex)
            {

            }
        }

        private void 打开空间ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.RestoreDirectory = true;

            openFileDialog1.Filter = "*.ae|*.ae|*.*|*.*";
            if(openFileDialog1.ShowDialog() == DialogResult.OK)
            {

            }
        }

    }
}

